package com.wave.wavesystem.serve.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.wave.common.model.KV;
import com.wave.common.model.Result;
import com.wave.wavesystem.serve.enums.menu.MenuStatusEnum;
import com.wave.wavesystem.serve.enums.post.PostStatusEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/common")
@Tag(name = "公共接口-CommonController")
public class CommonController {

    @PostMapping("/photo/captcha")
    @Operation(summary = "获取图片验证码")
    public Result<KV<String, String>> photoCaptcha(HttpServletResponse response) {
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
        response.setHeader("captcha", lineCaptcha.getCode());
        KV<String, String> kv = new KV<>();
        kv.setKey(lineCaptcha.getImageBase64());
        kv.setValue(lineCaptcha.getCode());
        return Result.success(kv);
    }

    @GetMapping("/menuStatusEnum")
    @Operation(summary = "菜单状态枚举")
    public Result<List<KV<String, Integer>>> menuStatusEnum() {
        return Result.success(MenuStatusEnum.list());
    }

    @GetMapping("/postStatusEnum")
    @Operation(summary = "帖子状态枚举")
    public Result<List<KV<Integer, String>>> postStatusEnum() {
        return Result.success(PostStatusEnum.list());
    }

}
